package com.aiguigu.JVM;

public class Example {
    public static void main(String[] args) {
        String lockA = "lockA";
        String lockB = "lockB";

        new Thread(new DeadLock(lockA,lockB),"aaa").start();
        new Thread(new DeadLock(lockB,lockA),"bbb").start();
    }
}
class DeadLock implements Runnable{
    private String lockA;
    private String lockB;

    public DeadLock(String lockA, String lockB) {
        this.lockA = lockA;
        this.lockB = lockB;

        /*
        * jps  java版ps(linux)命令
        * jstack 进程号
        * */
    }


    @Override
    public void run() {
        synchronized (lockA){
            System.out.println(Thread.currentThread().getName()+"自己持有"+lockA+"尝试获得"+lockB);
            synchronized (lockB){
                System.out.println(Thread.currentThread().getName()+"自己持有"+lockB+"尝试获得"+lockA);
            }
        }
    }
}

